function getLbs(location, flag) {
	var url = "http://api.map.baidu.com/geosearch/v3/nearby?callback=?";
	$.getJSON(url, {
		'q': '',
		'location': location,
		'radius': 3000,
		'page_size': 10,
		'geotable_id': 75274,
		'sortby': 'distance:1',
		'ak': 'nbZYk6ZZiBm3hwqNYzYRq5z6'
	},
	function(e) {
		if (flag) {
			$("#over").css("display", "none");
			$("#layout").css("display", "none");
		}
		if (e.status != 0) {
			alert("额,服务器抽风中,请稍后重试!");
			return;
		}
		renderList(e);
	});
}
function send_loc() {
	$("#over").css("display", "block");
	$("#layout").css("display", "block");
	$("#allmap").css("display", "none");
	$(".deal-btn").css("display", "none");
	$(".current-weizhi").css("display", "block");
	$(".v3").css("display", "block");
	$(".goods-list-title").text("最近修车点");
	var gc = new BMap.Geocoder();
	gc.getLocation(new BMap.Point(map.getCenter().lng, map.getCenter().lat),
	function(rs) {
		var addComp = rs.addressComponents;
		var address = addComp.city + addComp.district + addComp.street + addComp.streetNumber;
		if(a_b_loc){
			$("#tip-address").html("当前位置: "+address);
		}else{
			$(".locbar-txt").html(address);
		}
		
		
	});
	var lacation = map.getCenter().lng + "," + map.getCenter().lat;
	getLbs(lacation, 1);
}
function cancel_loc() {
	$("#allmap").css("display", "none");
	$(".deal-btn").css("display", "none");
	$(".current-weizhi").css("display", "block");
	$(".v3").css("display", "block");
	$(".goods-list-title").text("最近修车点");
}
function openMap() {
	$(".current-weizhi").css("display", "none");
	$(".v3").css("display", "none");
	$("#allmap").css("display", "block");
	$(".deal-btn").css("display", "block");
	var mapBoxHeight = $(window).height() * 0.7;
	$('#allmap').css({
		height: mapBoxHeight + 'px'
	});
	$(".goods-list-title").text("将标注点拖到您所在的位置,点击确定提交即可");
	map = new BMap.Map("allmap");
	if (pt_lng == 0 || pt_lat == 0) {
		if (remote_ip_info['city']) {
			map.centerAndZoom(remote_ip_info['city'], 12);
		} else {
			alert("额,服务器抽风中,请稍后重试!");
		}
	} else {
		pt = new BMap.Point(pt_lng, pt_lat);
		map.centerAndZoom(pt, 12);
	}
	map.enableDragging();
	var myIcon = new BMap.Icon("http://m.xq517.com/static/images/0.png", new BMap.Size(25, 50));
	var marker1 = new BMap.Marker(new BMap.Point(map.getCenter().lng, map.getCenter().lat), {
		icon: myIcon
	});
	map.addOverlay(marker1);
	map.addEventListener("touchmove",
	function() {
		marker1 = new BMap.Marker(new BMap.Point(map.getCenter().lng, map.getCenter().lat), {
			icon: myIcon
		});
		map.clearOverlays();
		map.addOverlay(marker1);
	});
	map.addEventListener("moveend",
	function() {
		marker1 = new BMap.Marker(new BMap.Point(map.getCenter().lng, map.getCenter().lat), {
			icon: myIcon
		});
		map.clearOverlays();
		map.addOverlay(marker1);
	});
	map.addEventListener("zoomend",
	function() {
		marker1 = new BMap.Marker(new BMap.Point(map.getCenter().lng, map.getCenter().lat), {
			icon: myIcon
		});
		map.clearOverlays();
		map.addOverlay(marker1);
	});
}
function renderList(res) {
	var content = res.contents;
	$('#listBoby').html('');
	if (content.length == 0) {
		$('#listBoby').append("<li class='single_item'><div class='item-name'> <h2>您附近没有维修站!!(你可以用手动定位,将位置换到城市中心地带试试)</h2></div></li>");
		return;
	}
	$.each(content,
	function(i, item) {
		$('#listBoby').append("<li class='single_item'> " + "<div class='item-name'> <h3>维修站：" + item.title + "</h3>" + "<h2>地址：" + item.address + "</h2>" + "<a class='a-tel'  href='tel:" + getNum(item.phone) + " '> <b class='icon tel'></b>" + item.phone + "</a><a class='a-distance'>" + item.distance + "米</a></div></li>");
	});
}
function getNum(text) {
	var value = text.replace(/[^0-9]/ig, "");
	return value
}